package com.example.mybatis.handler.type.handler.impl;

import com.example.mybatis.handler.type.JdbcType;
import com.github.houbb.heaven.util.lang.ObjectUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CharacterTypeHandler   extends  AbstractTypeHandler<Character>  {
    @Override
    public void setParameter(PreparedStatement ps, int i, Character parameter, JdbcType jdbcType) throws SQLException {
     ps.setString(i,parameter.toString());
    }

    @Override
    public Character getResult(ResultSet rs, String columnName) throws SQLException {
        String  text =         rs.getString(columnName);
        if (ObjectUtil.isEmpty(text)){
            return null;
        }
        return text.charAt(0);
    }

    @Override
    public Character getResult(ResultSet rs, int columnIndex) throws SQLException {
        String text =   rs.getString(columnIndex);
        if (ObjectUtil.isEmpty(text)){
            return null;
        }
        return text.charAt(0);
    }
}
